package com.kotiln.lgc.lib_network.net;


import androidx.appcompat.app.AppCompatDialog;


import com.kotiln.lgc.lib_network.net.callback.IError;
import com.kotiln.lgc.lib_network.net.callback.IFailure;
import com.kotiln.lgc.lib_network.net.callback.IRequest;
import com.kotiln.lgc.lib_network.net.callback.ISuccess;

import java.io.File;
import java.util.WeakHashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RestClientBuilder {

    private String mUrl;
    private static final WeakHashMap<String, Object> PARAMS = RestCreator.getParams();
    private IRequest mIRequest;
    private ISuccess mISuccess;
    private IError mIError;
    private IFailure mIFailure;
    private RequestBody mBody;
    private File mFile;
    private AppCompatDialog mDialog;
    private String mDownloadDir = null;
    private String mExtension = null;
    private String mName = null;

    RestClientBuilder() {
    }

    public RestClientBuilder url(String url) {
        mUrl = url;
        return this;
    }

    public RestClientBuilder params(WeakHashMap<String, Object> params) {
        PARAMS.putAll(params);
        return this;
    }

    public RestClientBuilder params(String key, Object value) {
        PARAMS.put(key, value);
        return this;
    }

    public RestClientBuilder raw(String raw) {
        mBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), raw);
        return this;
    }

    public RestClientBuilder request(IRequest request) {
        mIRequest = request;
        return this;
    }

    public RestClientBuilder success(ISuccess iSuccess) {
        mISuccess = iSuccess;
        return this;
    }

    public RestClientBuilder error(IError iError) {
        mIError = iError;
        return this;
    }

    public RestClientBuilder failure(IFailure iFailure) {
        mIFailure = iFailure;
        return this;
    }

    public RestClientBuilder body(RequestBody body) {
        mBody = body;
        return this;
    }

    public RestClientBuilder file(File file) {
        mFile = file;
        return this;
    }

    public RestClientBuilder file(String file) {
        mFile = new File(file);
        return this;
    }

    public final RestClientBuilder name(String name) {
        this.mName = name;
        return this;
    }

    public final RestClientBuilder dir(String dir) {
        this.mDownloadDir = dir;
        return this;
    }

    public final RestClientBuilder extension(String extension) {
        this.mExtension = extension;
        return this;
    }

    public RestClientBuilder dialog(AppCompatDialog dialog) {
        mDialog = dialog;
        return this;
    }

    public final RestClient build() {
        return new RestClient(mUrl, PARAMS, mDownloadDir, mExtension, mName, mIRequest, mISuccess, mIError, mIFailure, mBody, mFile, mDialog);
    }
}
